<template>
    <div>
        <el-button size="small" type="primary" @click="goback">返回一番赏列表</el-button>
        <el-button size="small" type="primary" @click="addGoods">添加赏品</el-button>
        <el-table ref="multipleTable" border :data="quanjuGoods" tooltip-effect="dark" style="width: 100%"
            @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55">
            </el-table-column>
            <el-table-column label="ID" prop="id" width="40">
            </el-table-column>
            <el-table-column label="赏品名称" prop="name">
                <template v-slot="scope">{{ scope.row.name }}</template>
            </el-table-column>
              <el-table-column prop="title" label="赏品图片">
                    <template v-slot="scope">
                        <div class="display_url">
                            <img :src="scope.row.display_url">
                        </div>
                    </template>
                </el-table-column>
            <el-table-column prop="good_title" label="赏品类型">
                <template v-slot="scope">
                    <el-button type="primary" size="mini" round>{{ scope.row.good_rarity }}</el-button>
                </template>
            </el-table-column>
            <el-table-column label="显示价格" prop="name">
                <template v-slot="scope">
                    <el-button type="warning" size="mini">￥{{ format_money(scope.row.price) }}</el-button>
                </template>
            </el-table-column>
            <el-table-column label="回收价格" prop="name">
                <template v-slot="scope">  <el-button type="warning" size="mini">￥{{ format_money(scope.row.recovery_price) }}</el-button></template>
            </el-table-column>
            <el-table-column prop="good_desc" label="预售类型">
               <template v-slot="scope">
                    <el-button v-if="scope.row.good_presale_type== '现货'" type="success" size="mini" round>现货</el-button>
                    <el-button v-else type="warning" size="mini" round>预售</el-button>
               </template>
            </el-table-column>
            <el-table-column label="操作" width="120">
                <template v-slot="scope">
                    <a class="editGood" @click="edit(scope.row.good_uuid)">编辑</a>
                    <a class="delGood" @click="del(scope.row.good_uuid)">删除</a>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import { StatusCodes } from 'http-status-codes'
import yifan from '../../../../api/jurisdiction'
import {format_money} from "../../../../utils/format";
export default {
    data() {
        return {
            quanjuGoods:[],
            game_uuid: '',
            game_methods: [],
        }
    },
    created() {
        this.getYifanshangGoods()
        console.log(this.$route.params)
    },
    methods: {
      format_money,
        goback() {
            this.$router.push("/layout/choushangguanli/yifanshang")
        },
        addGoods() {
            this.$router.push("/layout/choushangguanli/addyifanshanggoods")
        },
        getYifanshangGoods() {
            this.game_uuid = this.$route.params.game_id
            // if (localStorage.getItem("yifanshang_game_uuid")) {
                yifan.yifanshangGoods({ params: { game_uuid: localStorage.getItem("yifanshang_game_uuid")} })
                .then((res) => {
                    console.log('赏品池子列表',res)
                    this.quanjuGoods = res.data.data
                }).catch((err) => {
                    
                })
            // }
        },
        handleSelectionChange() {

        },
        edit(id) {
            console.log('editid', id)
        },
        del(id) {
            console.log('game_uuid',this.game_uuid)
            console.log('good_uuid',id)
              this.$confirm('请确认是否删除?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
                  yifan.delyifangoods({
                      data: {
                          game_uuid: localStorage.getItem("yifanshang_game_uuid"),
                          good_uuid: id,
                      }
                  }).then((res) => {
                    console.log('删除', res)
                    this.getYifanshangGoods()
                    this.$message.success("删除成功!")
                }).catch((err) => {
                    console.log("请求错误",err)
                     this.getYifanshangGoods()
                })
              }).catch((error) => {
                console.log('删除',error)
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });

            console.log('delid', id)
        }
    },

}
</script>

<style lang="less" scoped>
.display_url,
.display_url img {
    width: 60px;
    height: 60px;
}

.el-table {
    margin-top: 10px;
}

a {
    display: inline-block;
    margin-right: 5px;
    padding: 1px 7px;
    height: 23px;
    border-radius: 23px;
    font-size: 12px;
    background: #009688;
    color: white;
    cursor: pointer;
}

.delGood {
    background: #ff5722;
}</style>